package com.longge;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-04-21 00:02
 */
public class Flatten {

    Node2 dum = new Node2(0);
    Node2 cur = dum;

    public Node2 flatten(Node2 head) {
        if (head == null) return null;
        cur.next = new Node2(head.val);
        cur.next.prev = cur;
        cur = cur.next;
        flatten(head.child);
        flatten(head.next);
        return dum.next;
    }

    public static void main(String[] args) {
        Node2 node2 = new Node2(1);
        Node2 node3 = new Node2(2);
        Node2 node4 = new Node2(3);
        Node2 node5 = new Node2(4);
        node2.next=node3;
        node3.prev=node2;
        node3.next=node4;
        node4.prev=node3;
        node4.next=node5;
        node5.prev=node4;
        Flatten flatten = new Flatten();
        Node2 res = flatten.flatten(node2);
        System.out.println(res);
    }
}
